// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SET_CDImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.sunwayhorizo.health.business.dto.DictionaryDTO;
import com.sunwayhorizo.health.ets.base.service.ETSService;
import com.sunwayhorizo.health.ets.exceptions.ETSException;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CD;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.IVL_CD;
import com.sunwayhorizo.health.hl7.datatypes.SET_CD;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            SETCommonImpl, ANYImpl, BLImpl, CDImpl, 
//            CSImpl, STImpl, TYPEImpl, UIDImpl

public class SET_CDImpl extends SETCommonImpl
    implements SET_CD
{

    public static final String RCS_ID = "$Header: SET_CDImpl.java 115.31 2005/09/16 09:22:46 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: SET_CDImpl.java 115.31 2005/09/16 09:22:46 amchanda noship $", "oracle.apps.ctb.hl7.types.common");
    private static final SET_CD nullNI = new SET_CDImpl(CSImpl.valueOf("NI"));
    private static final SET_CD nullOTH = new SET_CDImpl(CSImpl.valueOf("OTH"));
    private static final SET_CD nullNINF = new SET_CDImpl(CSImpl.valueOf("NINF"));
    private static final SET_CD nullPINF = new SET_CDImpl(CSImpl.valueOf("PINF"));
    private static final SET_CD nullUNK = new SET_CDImpl(CSImpl.valueOf("UNK"));
    private static final SET_CD nullASKU = new SET_CDImpl(CSImpl.valueOf("ASKU"));
    private static final SET_CD nullNAV = new SET_CDImpl(CSImpl.valueOf("NAV"));
    private static final SET_CD nullMSK = new SET_CDImpl(CSImpl.valueOf("MSK"));
    private static final SET_CD nullNA = new SET_CDImpl(CSImpl.valueOf("NA"));
    private static final SET_CD nullNASK = new SET_CDImpl(CSImpl.valueOf("NASK"));

    public static SET_CD valueOf(CD acd[])
    {
        return new SET_CDImpl(acd);
    }

    public static SET_CD valueOf(CD cd)
    {
        return new SET_CDImpl(cd);
    }

    public static SET_CD valueOf(Set set)
    {
        return new SET_CDImpl(set);
    }

    public static SET_CD nullSET_CD()
    {
        return new SET_CDImpl(((CS) (null)));
    }

    /**
     * 修改CD类型改变后带来的错误
     *
     * jinzw
     * 2010-11-15
     * @param etsservice
     * @param as
     * @return
     * @throws ETSException
     */
    public static SET_CD newSET_CD(ETSService etsservice, String as[])
        throws ETSException
    {
        List<DictionaryDTO> aconcept  = etsservice.findConcepts(as, true);
        HashSet hashset = new HashSet();
         
        for(int j = 0; j < aconcept.size(); j++)
        {
        	DictionaryDTO concept = (DictionaryDTO)aconcept.get(j);
            String s1 = concept.getConceptCode();
            String s2 =  "";
            String cn = concept.getConceptName(); // ets术语名称 mCodeName
          
            String s3 = concept.getVersionName();
             
            String en = concept.getCodingschemeEnName(); //英文编码 mCodeSystemEnName
            String ch = concept.getCodingschemeChName(); //中文编码 mCodeSystemChName
            String s5 = concept.getCodingschemeOid();
            ST st = STImpl.valueOf(s1);
            com.sunwayhorizo.health.hl7.datatypes.UID uid = UIDImpl.valueOf(s5);
            ST sen = STImpl.valueOf(en); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeSystemEnName
            ST sch = STImpl.valueOf(ch); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeSystemChName
            ST scn = STImpl.valueOf(cn); //对应com.sunwayhorizo.health.hl7.datatypes.common.CDImpl中的mCodeName
            ST st2 = STImpl.valueOf(s3);
            ST st3 = STImpl.valueOf(s2);
            CDImpl cdimpl = new CDImpl(etsservice, st, uid, sen,sch, st2, st3,scn, null, null, null);
            hashset.add(cdimpl);
        }

        return valueOf(hashset);
    }

    protected SET_CDImpl(CD acd[])
    {
        if(acd == null)
            throw ANYImpl.newNullException("SET<CD>", "constructor", "elements");
        for(int i = 0; i < acd.length; i++)
            if(acd[i] != null && acd[i].isNull().isFalse() && acd[i].dataType().equal(com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.CD).isTrue())
                mSet.add(acd[i]);

    }

    protected SET_CDImpl(CD cd)
    {
        if(cd == null || cd.isNull().isTrue() || cd.dataType().equal(com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.CD).isFalse())
        {
            throw ANYImpl.newNullException("SET<CD>", "constructor", "element");
        } else
        {
            mSet.add(cd);
            return;
        }
    }

    public SET_CDImpl(Set set)
    {
        super(set);
    }

    public SET_CDImpl(CS cs)
    {
        super(cs);
    }

    public BL contains(CD cd)
    {
        return BLImpl.valueOf(mSet.contains(cd));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_CD;
    }

    public BL contains(SET_CD set_cd)
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return BLImpl.valueOf(mSet.containsAll(set_cd.toSet()));
    }

    public SET_CD union(SET_CD set_cd)
    {
        if(isNull().isTrue())
            if(set_cd.isNull().isTrue())
                return this;
            else
                return set_cd;
        if(set_cd.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.addAll(set_cd.toSet());
            return valueOf(hashset);
        }
    }

    public SET_CD union(CD cd)
    {
        if(cd.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.add(cd);
            return new SET_CDImpl(hashset);
        }
    }

    public SET_CD except(CD cd)
    {
        if(isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.remove(cd);
            return new SET_CDImpl(hashset);
        }
    }

    public SET_CD except(SET_CD set_cd)
    {
        if(isNull().or(set_cd.isNull()).isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            Set set = set_cd.toSet();
            hashset.removeAll(set);
            return new SET_CDImpl(hashset);
        }
    }

    public SET_CD intersection(SET_CD set_cd)
    {
        if(isNull().or(set_cd.isNull()).isTrue())
            return nullSET_CD();
        HashSet hashset = new HashSet();
        for(Iterator iterator = set_cd.toSet().iterator(); iterator.hasNext();)
        {
            CD cd = (CD)iterator.next();
            if(mSet.contains(cd))
                hashset.add(cd);
        }

        return valueOf(hashset);
    }

    public IVL_CD hull()
    {
        throw ANYImpl.newUnsupportedException("SET<CD>", "hull");
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_CD))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_CD set_cd = (SET_CD)any;
            return BLImpl.valueOf(equalsSet(set_cd.toSet()));
        }
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof CD) && ((CD)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_CD nullSET_CD(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
